//
//  YXHomeTitleView.swift
//  yanXiangWeiBo
//
//  Created by 颜祥 on 15/12/22.
//  Copyright © 2015年 yanxiang. All rights reserved.
//

import UIKit

class YXHomeTitleView: UIButton
{
    init(imageName: String, title: String)
    {
        super.init(frame: CGRectZero)
        // 设置图片
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        // 设置标题
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        // 按钮自适应
        sizeToFit()
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 自动布局，重置图片和文字的位置
    override func layoutSubviews()
    {
        super.layoutSubviews()
        
        // 文字在左边
        self.titleLabel?.frame.origin.x = 0
        
        // 图片在右边
        self.imageView?.frame.origin.x = (self.titleLabel?.frame.width)! + 3
        
    }
    
    
    
    
    
    
}

